module array_loc_mthd;

string SA[10], qs[$];
int IA[*], qi[$] ;

initial
begin
   //SA[1:5] = {"Bob","Abc","Bob","Henry","John"}; //gives a WARNING
   // array initialization has to be within '{} for each of the element and one '{} for the whole array
   SA[1:5] = '{ '{"Bob"}, '{"Abc"}, '{"Bob"}, '{"Henry"}, '{"John"} }; // THE WAY IT SHOULD BE
   
   IA[2]=3;
   IA[3]=13;
   IA[5]=43;
   IA[8]=36;
   IA[55]=237;
   IA[28]=39;

   // find all items greater than 5
   qi = IA.find(x) with (x > 5);
   for ( int j=0; j<qi.size; j++)
      $write("%0d_", qi[j]);
   $display("");
   
   // find all indexes of all items equal to 3
   // ERROR DISPLAYED FOR THIS BLOCK
   // Can't use index methods on wildcard assoc. arrays.
   // since IA is declared as IA[*], index methods can't be used on such arrays
     // qi = IA.find_index(x) with (x == 3);
     // for ( int j=0; j<qi.size; j++)
     //    $write("%0d_", qi[j] );
     // $display("");
   
   // find first item equal to Bob
   qs = SA.find_first with (item == "Bob"); //'item' is a keyword
                                            // if 'item' is used, you need not mention brackets after the method
                                            // If any other variable is used, bracket should be used after the method; 
                                            // E.g., qs = SA.find_first(x) with (x=="Bob");
                                            // it cannot be qs = SA.find_first with (x=="Bob");
                                            // it results in loading error
   for ( int j=0; j<qs.size; j++)
      $write("%s_", qs[j]);
   $display("");

   // find the last item equal to "Henry"
   qs = SA.find_last(y) with ( y.tolower == "henry"); // note the usage of tolower function
   for ( int j=0; j<qs.size; j++)
      $write("%s_", qs[j]);
   $display("");

   // find index of last item greater than Z
   // no element is greater than "Z", so a null array is returned
   // REMEMBER that first the capital letters and then small letters in the ASCII representation
   qi = SA.find_index(xx) with ( xx > "Z");
   for ( int j=0; j<qi.size; j++)
      $write("%0d_", qi[j]);
   $display("");

   // find the smallest element
   qi = IA.min;
   for ( int j=0; j<qi.size; j++)
      $write("%0d_", qi[j]);
   $display("");

   // find the STRING with largest numerical value
   qs = SA.min with ( item.atoi );
   for ( int j=0; j<qs.size; j++)
      $write("%s_", qs[j]);
   $display("");
   // the result of the above block has one element
   // that's why an underscore is displayed on screen
   // probably, the max value is referred to the the null array elements?!


   // find all unique string
   qs = SA.unique;
   for ( int j=0; j<qs.size; j++)
      $write("%s_", qs[j]);
   $display("");

   // find all unique lower case string
   qs = SA.unique(s) with (s.tolower) ;
   for ( int j=0; j<qs.size; j++)
      $write("%s_", qs[j]);
   $display("");

   // find indexes of all unique string
   qi = SA.unique_index;
   for ( int j=0; j<qi.size; j++)
      $write("%0d_", qi[j]);
   $display("");

end

endmodule
